package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.EmpService;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("login")
public class LoginController {

    @Autowired
    private UserService userService;


    @RequestMapping("toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("login")
    @ResponseBody
    public String login (String uname , String pwd, HttpSession session){
        if (uname!=null && pwd!=null){
            User user=userService.findByName(uname,pwd);
            session.setAttribute("user",user);
            return "redirect:emp/xx/index";
        }
        return "login";
    }
}
